package com.etc.controller;

import com.etc.dto.Result;
import com.etc.entity.Pay;
import com.etc.service.PayService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private PayService payService;


    @GetMapping("/paylistbyid")
    public @ResponseBody
    Result getPayPatientDetailListById(@RequestParam String payId) {
        Result result = new Result();
        Pay pay = new Pay();
        pay.setPayId(payId);
        List<Pay> payList = payService.getPayPatientDetailListSelective(pay);
        result.ok(payList);
        return result;
    }

    @GetMapping("/payContent")
    public @ResponseBody
    Result updatePayContent(@RequestParam String patientName, @RequestParam String content) {
        Result result = new Result();
        boolean flag = payService.updatePayContent(patientName, content);
        if (flag) {
            result.ok(true);
        } else {
            result.fail(0, "更改失败");
        }

        return null;
    }

    @GetMapping("/paylist")
    public @ResponseBody
    Result getPayOrderDoctorPatientList(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        Result result = new Result();
        //List<Pay> payOrderDoctorPatientList = payService.getPayOrderDoctorPatientList();
        PageInfo<Pay> payOrderDoctorPatientListByPage = payService.getPayOrderDoctorPatientListByPage(pageNum, pageSize);
        result.ok(payOrderDoctorPatientListByPage);
        return result;
    }
    @GetMapping("/payListById")
    public @ResponseBody Result getList(@RequestParam String patientId){
        Result result = new Result();
        List<Pay> payList =payService.getPayListByPatientId(patientId);
        if(!payList.isEmpty()){
            result.ok(payList);
        }else {
            result.fail(0,"没有相关数据");
        }


        return result;
    }
}
